<?php
/*!
 * @version		$Id: config.cfg.php 8841 2007-12-07 20:14:22Z $
 * @package		diduo: Makes the friend community in Wuhan 
 * @link        http://www.diduo.net
 * @author      moolao <moolao@diduo.net>
 * @abstract    config.cfg.php: Initialization system  configuration
 * @copyright	Copyright (C) 2007 - 2008 diduo.net development team. All rights reserved.
 */
// no direct access
defined( '_DEXEC' ) or die( 'Restricted access' );

// set the directory separator
defined( 'DS' ) || define( 'DS', DIRECTORY_SEPARATOR );

// start all page session
session_start();

/**
 * System Initialization configuration
 * @package diduo
 */
class Config{

	/** @access private */
	private $_errMsg        =  '';     
	private $_error_report  =  true;   
	private $_error_halt    =  true;   
    /**#@-*/

	/**
	 * A hack to support __construct() on PHP 4
	 *
	 * Hint: descendant classes have no PHP4 class_name() constructors,
	 *
	 * @return	Object
	 */
	public function Config()
	{
		$args = func_get_args();
		call_user_func_array( array( &$this, '__construct' ), $args );
	}

	/**
	 * Class constructor, overridden in descendant classes.
	 */
	protected function __construct() {}

	/**
	 * Returns a property of the object or the default value if the property is not set.
	 *
	 * @param	string $name The name of the property
	 * @param	mixed  $value The default value
	 * @return	mixed The value of the property
 	 */
	public function setVal( $name, $value = null )
	{
		if( isset( $this->$name ) ) { return $this->$name; }
		return $value;
	}
 
	/**
	 * Returns an associative array of object properties
	 *
	 * @param	boolean $name If true, returns only the public properties
	 * @return	array
 	 */
	public function getVal( $name = true )
	{
		$vars  = get_object_vars($this);
		if($name)
		{
			foreach ( $vars as $key => $value )
			{
				if ( '_' == substr( $key, 0, 1 ) ) {
					unset( $vars[$key] );
				}
			}
		}
		return $vars;
	}

	/**
	 * Add an error message halt system
	 * 
	 * @param string $msg 
	 * @return	string This name of this class
 	 */
   public function catchErr( $msg )
   {
      if ( empty( $this->_errMsg ) ) { $this->_errMsg = $msg; }
      if ( $this->_error_report )    { print  $this->_errMsg; }
      if ( $this->_error_halt )      { exit; }
      return false;
   }

	/**
	 * Add an error message halt system
	 * 
	 * @param boolean $exit
	 * @return	string This name of this class
 	 */
	public function errHalt( $exit = false )
	{
      if (!empty($this->_errMsg))
      {
          print $this->_errMsg;
          if ( $exit ) { exit; }
      }
	}

	/**
	 * Object-to-string conversion.
	 * Each class can override it as necessary.
	 *
	 * @return	string This name of this class
 	 */
	public function toString()
	{
		return get_class($this);
	}

} // end class
?>